package org.sanguine.study.hometasks.second.auxiliary;

public class Cell implements Comparable<Cell> {
	public final int x;
	public final int y;
	private final long distance;

	public Cell(int x, int y, int referenceX, int referenceY) {
		this.x = x;
		this.y = y;
		int ax = x - referenceX;
		int ay = y - referenceY;
		distance = (long)Math.sqrt((ax * ax + ay * ay));
	}

	@Override
	public int compareTo(Cell o) {
		if (distance == o.distance)
			if (x == o.x) return y - o.y;
			else return x - o.x;

		return (int)(distance - o.distance);
	}

	@Override
	public String toString() {
		return "(" + x + ", " + y + ", distance=" + distance + ")";
	}
}
